using System.Data.Linq;
using System.Linq;

namespace Exercises
{
    partial class Employee
    {
        public EntitySet<Territory> Territories
        {
            get
            {
                DataClassNorthwindDataContext context = new DataClassNorthwindDataContext();
                EntitySet<Territory> territories = new EntitySet<Territory>();
                using (context)
                {
                    var res =
                        from employeeTer in context.EmployeeTerritories
                        join terr in context.Territories on employeeTer.TerritoryID equals terr.TerritoryID
                        where employeeTer.EmployeeID == this.EmployeeID
                        select terr;
                    foreach (var item in res)
                    {
                        territories.Add(item);
                    }
                }
                return territories;
            }
        }
    }
}
